'use strict';

const cluster = require('cluster');
const os = require('os');
const app = require('./app');

if (cluster.isMaster) {
    cluster.on('fork', function(worker) {
        console.log('worker:' + worker.process.pid + '*****Start*****');
    });

    cluster.on('exit', function(worker, code, signal) {
        console.log('worker:' + worker.process.pid + '!!!!!Dead!!!!!');
        cluster.fork();
    });

    for (let i = 0; i < os.cpus().length; i++) {
        cluster.fork();
    }
} else {
    app.listen(80);
}